<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
if (eregi(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) || eregi(".inc.php",$_SERVER['PHP_SELF'])) {
	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
	exit;
}


if (!isset($_GET['cat'])) {
	
// get the category listings
$getTopCat = mysql_query("SELECT * FROM affiliSt_linkcategories WHERE parent = '0' ORDER BY name ASC");
$topCat = mysql_fetch_assoc($getTopCat);


} else {
	
// get the category listings
$sql = sprintf("SELECT * FROM affiliSt_linkcategories WHERE parent = %d ORDER BY name ASC",
				quote_smart($_GET['cat']));
$getTopCat = mysql_query($sql, $databaseConnect) or die(mysql_error());
$topCat = mysql_fetch_assoc($getTopCat);
	
}
	
	
	

$box_content = new XTemplate ("skins/".$configSkin['value']."/styleTemplates/linkcategories.tpl");

$box_content->assign("ADDLINK", $installDir['value'].'index.php?case=links&ld=1&add=1');
	
if ($topCat) {

	if (!isset($_GET['cat'])) {
	
		do {
			$box_content->assign("CATNAME", $topCat['name']);
			$box_content->assign("CATCOUNT", $topCat['counter']);
			
			if ($navOpt[7] == 1) {
			// html perma
			$box_content->assign("CATLINK", $installDir['value']."links/1/".$topCat['id'].'.html');
			} else {
			// php link
			$box_content->assign("CATLINK", $installDir['value']."index.php?case=links&ld=1&cat=".$topCat['id']);
			}
			
			
			
			
			
			
			// get the sub category listings
			$sql = sprintf("SELECT * FROM affiliSt_linkcategories WHERE parent = %d ORDER BY name ASC LIMIT 4",
							quote_smart($topCat['id']));
			$getSubCat = mysql_query($sql, $databaseConnect) or die(mysql_error());
			$subCat = mysql_fetch_assoc($getSubCat);
			
			do { 
			
				if ($subCat['id'] != NULL) {
				
					$box_content->assign("SUBCATNAME", $subCat['name']);
					$box_content->assign("SUBCATCOUNT", $subCat['counter']);
					
					
			
					if ($navOpt[7] == 1) {
					// html perma
					$box_content->assign("SUBCATLINK", $installDir['value']."links/1/".$subCat['id'].'.html');
					} else {
					// php link
					$box_content->assign("SUBCATLINK", $installDir['value']."index.php?case=links&ld=1&cat=".$subCat['id']);
					}
					
					$box_content->parse("categories.li.subli");
					
				$box_content->assign("SUBCATEND", "...");
					
				} else {
				$box_content->assign("SUBCATEND", "");
				}
				
			} while ($subCat = mysql_fetch_assoc($getSubCat));
			
			
			
			
			
			
			
			
			
			
			$box_content->parse("categories.li");
		
		} while ($topCat = mysql_fetch_assoc($getTopCat));





	// if cat is set get sub categories only
	} else {
	
	do {
			$box_content->assign("CATNAME", $topCat['name']);
			$box_content->assign("CATCOUNT", $topCat['counter']);
			
			if ($navOpt[7] == 1) {
			// html perma
			$box_content->assign("CATLINK", $installDir['value']."links/1/".$topCat['id'].'.html');
			} else {
			// php link
			$box_content->assign("CATLINK", $installDir['value']."index.php?case=links&ld=1&cat=".$topCat['id']);
			}
			
			$box_content->parse("categories.li");
		
	} while ($topCat = mysql_fetch_assoc($getTopCat));
	
	
	
	
	
	
	
	
	}

$box_content->parse("categories");
$box_content = $box_content->text("categories");
} else {
$box_content->parse("nocategories");
$box_content = $box_content->text("nocategories");
}
?>